package com.dapeng.jackson.annotations;

/**
 * @BelongProject study
 * @BelongPackage com.dapeng.jackson.annotations
 * @Description TODO
 * @ClassName JKByteFormat
 * @Author xupenghong
 * @Date 2024/9/13 15:56
 * @Version 1.0.0
 */

import com.dapeng.jackson.serializer.JKByteFormatSerializer;
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * 字节格式化
 */
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@JsonSerialize(using = JKByteFormatSerializer.class)
@JacksonAnnotationsInside
public @interface JKByteFormat {

    // 保留精度
    int scale() default 2;

    /**
     * 原数值类型
     */
    Unit type() default Unit.BYTE;

    /**
     * 转换后的数值类型
     */
    Unit convert();

    String unit() default "";

    enum Unit {
        BIT,
        BYTE,
        KB,
        MB,
        GB;
    }

}
